import request from '@/utils/request';
import service from '@/utils/axiosRequest';

/**
 * 查询所有工艺在途
 * @param params
 * @returns {Promise<any>}
 */
export async function allProcessOnline(params) {
  return request('/api/manTechnologyOnline/selectByPage/all', {
    method: 'GET',
    params,
    data: { ...params },
  });
}
/**
 * 查询指派给我的工艺在途
 * @param params
 * @returns {Promise<any>}
 */
export async function assignedToMeProcessOnline(params) {
  return request('/api/manTechnologyOnline/selectByPage/assignedToMe', {
    method: 'GET',
    params,
    data: { ...params },
  });
}
/**
 * 查询我指派的工艺在途
 * @param params
 * @returns {Promise<any>}
 */
export async function myAssignedProcessOnline(params) {
  return request('/api/manTechnologyOnline/selectByPage/myAssigned', {
    method: 'GET',
    params,
    data: { ...params },
  });
}

/**
 * 查询指定生产编号的生产情况统计
 * @param params
 * @returns {Promise<any>}
 */
export async function queryProductionStatusByProductionNo(params) {
  return request(`/api/productionStats/${params.productionNo}`, {
    method: 'GET',
  });
}

/**
 * 查询指定生产编号的工艺段生产情况统计
 * @param params
 * @returns {Promise<any>}
 */
export async function queryProductionProcessStatusByProductionNo(params) {
  return request(`/api/productionStats/process/${params.productionNo}`, {
    method: 'GET',
  });
}

/**
 * 接受工艺在途
 * @param params
 * @returns {Promise<any>}
 */
export async function receiveProcessOnline(params) {
  return request(`/api/manTechnologyOnline/receive/${params.pkId}`, {
    method: 'PUT',
  });
}

/**
 * 接受工艺在途
 * @param params
 * @returns {Promise<any>}
 */
export async function rejectProcessOnline(params) {
  return request(`/api/manTechnologyOnline/reject/${params.pkId}`, {
    method: 'PUT',
  });
}


/**
 * 流转工艺在途
 * @param params
 * @returns {Promise<any>}
 */
export async function transferProcessOnline(params) {
  return request(`/api/manTechnologyOnline/transfer`, {
    method: 'PUT',
    data: { ...params },
  });
}

/**
 * 获取当前工艺在途返工时的可用工艺
 * @param params
 * @returns {Promise<any>}
 */
export async function transferProcessAvailableProcess(params) {
  return request(`/api/manTechnologyOnline/getAvailableProcess/${params.productCode}/${params.nowProcessId}`, {
    method: 'GET'
  });
}

/**
 * 包装入库
 * @param params
 * @returns {Promise<any>}
 */
export async function transferProcessPacking(params) {
  return request(`/api/manTechnologyOnline/packing`, {
    method: 'PUT',
    data: { ...params },
  });
}

/**
 * 获取当前工艺段mi参数
 * @param params
 * @returns {Promise<any>}
 */
export async function queryProcessOnlineMi(params) {
  return request(`/api/manTechnologyOnline/mi/${params.processId}/${params.productCode}`, {
    method: 'GET',
  });
}

/**
 * 查询订单的流转历史
 * @param params
 * @returns {Promise<any>}
 */
export async function queryTransferHistory(params) {
  return request(`/api/techTransferHistory/${params.orderId}`, {
    method: 'GET',
  });
}

/**
 * 分配工艺段负责人
 * @param params
 * @returns {Promise<any>}
 */
export async function allocateManager(params) {
  return request(`/api/manTechnologyProcessAdm/allocateManager/${params.processId}/${params.admStaffIds}`, {
    method: 'POST',
  });
}

/**
 * 分页查询统计信息
 * @param params
 * @returns {Promise<any>}
 */
export async function queryProductionStats(params) {
  return request(`/api/productionStats/getByPage`, {
    method: 'GET',
    params,
  });
}

/**
 * 导出统计信息
 * @param params
 * @returns {Promise<any>}
 */
export async function exportProductionStats(params) {
  return request(`/api/productionStats/export`, {
    method: 'GET',
    params,
    data: { ...params },
  });
}

/**
 * WIP
 * @param params
 * @returns {Promise<any>}
 */
export async function queryWIPStatus(params) {
  return request(`/api/productionStats/WIPStats`, {
    method: 'GET',
    params,
  });
}

/**
 * 导出WIP
 * @param params
 * @returns {Promise<any>}
 */
export async function exportWIPStatus(params) {
  return request(`/api/productionStats/export/WIP`, {
    method: 'GET',
    responseType: 'blob',
    params,
  });
}

// 接口文档下载
export function exportWIPStatusFile() {
  const url = '/productionStats/export/WIP';
  return service.get(url, {}, true);
}
